//
//  RBArchiveTool.m
//  RMMaterialRed
//
//  Created by XBWH on 2024/3/5.
//

#import "RBArchiveTool.h"
//用户基本信息
#define RMMaterialRedUserInfoModelFilepath [[NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES) lastObject] stringByAppendingPathComponent:@"RMMaterialRedUserInfoModel.data"]

@implementation RBArchiveTool
///存储用户登录信息
+ (void)rb_saveUserModel:(RBUserModel *)userModel{
    NSError *error;
    NSData* userModelData = [NSKeyedArchiver archivedDataWithRootObject:userModel requiringSecureCoding:YES error:&error];
    [userModelData writeToFile:RMMaterialRedUserInfoModelFilepath atomically:YES];
}
///读取用户登录信息
+ (RBUserModel *)rb_userModel{
    NSError *error;
    NSData *userModelData = [NSData dataWithContentsOfFile:RMMaterialRedUserInfoModelFilepath];
    RBUserModel *userModel = (RBUserModel *)[NSKeyedUnarchiver unarchivedObjectOfClass:[RBUserModel class] fromData:userModelData error:&error];
    return userModel;
}

//是否登录了
+ (BOOL)isLogin {
    NSString *isLogin = [RBArchiveTool rb_userModel].userId;
    if ([RBTool rb_isEmptyStr:isLogin]) {
        return NO;
    }else{
        return YES;
    }
}

@end
